import ContextPadProvider from "bpmn-js/lib/features/context-pad/ContextPadProvider";
import type { Injector } from "didi";
import type EventBus from "diagram-js/lib/core/EventBus";
import type ContextPad from "diagram-js/lib/features/context-pad/ContextPad";
import Modeling from "bpmn-js/lib/features/modeling/Modeling.js";
import type ElementFactory from "bpmn-js/lib/features/modeling/ElementFactory";
import type Connect from "diagram-js/lib/features/connect/Connect";
import type Create from "diagram-js/lib/features/create/Create";
import type PopupMenu from "diagram-js/lib/features/popup-menu/PopupMenu";
import type Canvas from "diagram-js/lib/core/Canvas";
import type Rules from "diagram-js/lib/features/rules/Rules";
import type { Translate } from "diagram-js/lib/i18n/translate";
import type { Base } from "diagram-js/lib/model";

class RewriteContextPadProvider extends ContextPadProvider {
  constructor(
    config: any,
    injector: Injector,
    eventBus: EventBus,
    contextPad: ContextPad,
    // modeling: Modeling,
    modeling: any,
    elementFactory: ElementFactory,
    connect: Connect,
    create: Create,
    popupMenu: PopupMenu,
    canvas: Canvas,
    rules: Rules,
    translate: Translate
  ) {
    super(
      config,
      injector,
      eventBus,
      contextPad,
      modeling,
      elementFactory,
      connect,
      create,
      popupMenu,
      canvas,
      rules,
      translate,
      2000
    );

    this._contextPad = contextPad;
    this._modeling = modeling;
    this._elementFactory = elementFactory;
    this._connect = connect;
    this._create = create;
    this._popupMenu = popupMenu;
    this._canvas = canvas;
    this._rules = rules;
    this._translate = translate;

    this._autoPlace = injector.get("autoPlace", false);
  }

  getContextPadEntries(element: Base) {
    const actions: Record<string, any> = {};

    // 添加一个与edit一组的按钮
    actions["enhancement-op-1"] = {
      group: "edit",
      className: "enhancement-op",
      title: "扩展操作1",
      action: {
        click: function (e: Event) {
          alert("点击 扩展操作1");
        },
      },
    };

    // 添加一个新分组的自定义按钮
    actions["enhancement-op"] = {
      group: "enhancement",
      className: "enhancement-op",
      title: "扩展操作2",
      action: {
        click: function (e: Event) {
          alert("点击 扩展操作2");
        },
      },
    };

    return actions;
  }
}

export default RewriteContextPadProvider;
